package com.spudtech
{
    
    import flash.geom.*;
    import flash.display.*;
    
    import com.spudtech.graphics.*;
    import com.spudtech.collision.*;
    
    
    public class SpudScreen extends SpudCanvas
    {
        
        protected var _backColor : uint;
        
        protected var _background : Sprite;
        
        protected var _cameraArea : SpudRect;
        
        public function SpudScreen(width : uint, height : uint)
        {
            super(width, height);
            
            _background = new Sprite();
            
            _cameraArea = new SpudRect(new Point(0,0), new Point(width, height));
            
            _backColor = 0x000000;
            
            
        }
        
        public function get cameraArea() : SpudRect
        {
            return _cameraArea;
        }
        
        override public function render(offset : Matrix,
                                        clip_rect : Rectangle,
                                        draw_graphics : Graphics) : void
        {
            draw_graphics.clear();
            
            draw_graphics.beginFill(this.backColor,1.0);
            
            draw_graphics.drawRect(
                0,0,
                cameraArea.width,
                cameraArea.height
            );
            
            draw_graphics.endFill();
            
            
            if (SpudRoot.mainApp.scene != null)
            {
                // The transform for the scene rendering
                var scene_matrix : Matrix = new Matrix();
                
                // Rectangle area for the scene rendering
                //var scene_rect : Rectangle = new Rectangle(0,0,0,0);
                
                //scene_rect.x = cameraArea.left;
                //scene_rect.y = cameraArea.top;
                
                //scene_rect.width = cameraArea.width;
                //scene_rect.height = cameraArea.height;
                
                
                SpudRoot.mainApp.scene.render(
                        scene_matrix,
                        //scene_rect,
                        cameraArea.flashRect,
                        draw_graphics
                );
            }
            
        }
        
        public function get backColor() : uint
        {
            return _backColor;
        }
        public function set backColor(new_color : uint) : void
        {
            if (_backColor == new_color)
            {
                // The screen is already that color
                // We return, saving ourself the
                // effort of repainting the
                // background
                
                return;
                
            }
            
            _backColor = new_color;
            
        }
        
        public function get background() : Sprite
        {
            return _background;
        }
        
    }
    
}
